<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * @category	CosmoCommerce
 * @package 	CosmoCommerce_99Bill
 * @copyright	Copyright (c) 2009 CosmoCommerce,LLC. (http://www.cosmocommerce.com)
 * @contact :
 * T: +86-021-66346672
 * L: Shanghai,China
 * M:sales@cosmocommerce.com
 */
//include("Mobile_Detect.php");
class Globebill_Qiwi_Block_Redirect extends Mage_Core_Block_Template
{
	/**
	 * Order instance
	 */
	protected $_order;
	
	/**
	 *  Get order
	 *
	 *  @param    none
	 *  @return	  Mage_Sales_Model_Order
	 */
public function getOrder()
	{	
		//从session获取isrepayment是否重新支付和orderid订单号，烈
		$isRePayment = Mage::getSingleton("core/session")->getData("isrepayment");
		$IncrementId = Mage::getSingleton("core/session")->getData("repay_IncrementId");

		if ($this->_order == null) {
			$session = Mage::getSingleton('checkout/session');			
			$this->_order = Mage::getModel('sales/order');
			//这里判断是否为重新支付，烈
			if(!$isRePayment){
				$this->_order->loadByIncrementId($session->getLastRealOrderId());
			}else{
				$this->_order->loadByIncrementId($IncrementId);
			}
		}
		return $this->_order;
	}
	
	/**
	 * toHtml
	 *
	 * @return string
	 * @deprecated after 1.4.0.1
	 */
	protected function _toHtml()
	{
		$this->setTemplate('qiwi/redirect.phtml');

		return parent::_toHtml();

	}
	
	public function qiwiForm()
	{
		$standard = Mage::getModel('qiwi/payment');
		$form = new Varien_Data_Form();
		$form->setAction($standard->getQiwiUrl())
		->setId('qiwi_payment_checkout')
		->setName('qiwi_payment_checkout')
		->setMethod('post')
		->setUseContainer(true);
		foreach ($standard->setOrder($this->getOrder())->getStandardCheckoutFormFields() as $field => $value) {
			$form->addField($field, 'hidden', array('name' => $field, 'value' => $value));
		}
		
		$formHTML = $form->toHtml();
		
		return $formHTML;
	}

	public function iframeHeight()
	{
		$model        = Mage::getModel('qiwi/payment');	
		$iframeHeight = $model->getConfigData('iframe_height');
	
		return $iframeHeight;
	
	}
	

	

}